package projectisd.client;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class AfmeldenDelegate {
    private ProjectServiceAsync projectService = GWT.create(ProjectService.class);
    AfmeldenGUI gui;
    
    void listAfmeldingen() {
    	
    	// verzamel de aanwezige lessen voor de gui
    	projectService.listLessen(new AsyncCallback<List<Les>> () {
                    public void onFailure(Throwable caught) {
                    	List<Les> result = null;
                    	gui.service_lessenListRetrievedFromService(result);
                    }
        
                    public void onSuccess(List<Les> result) {
                        gui.service_lessenListRetrievedFromService(result);
                    }
        }//end of inner class
        );//end of listLessen method call.    	 	
    	
    	projectService.listAfmeldingen(new AsyncCallback<List<Afmelden>> () {
                    public void onFailure(Throwable caught) {
                        gui.service_eventListAfmeldingenFailed(caught);
                    }
        
                    public void onSuccess(List<Afmelden> result) {
                        gui.service_eventListRetrievedFromService(result);
                        
                    }
        }//end of inner class
        );//end of listLes method call.
    }
    
    void addAfmelden(final Afmelden afmelden) {
    	projectService.addAfmelden(afmelden, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventAddAfmeldenFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventAddAfmeldenSuccessful();
            }
        }//end of inner class
        );//end of addLes method call.        
    }

    void updateAfmelden(final Afmelden afmelden) {
    	projectService.updateAfmelden(afmelden, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventUpdateAfmeldenFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventUpdateSuccessful();
            }
        }//end of inner class
        );//end of updateLes method call.        
    }

    void removeAfmelden(final Afmelden afmelden) {
    	projectService.removeAfmelden(afmelden, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventRemoveAfmeldenFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventRemoveAfmeldenSuccessful();
            }
        }//end of inner class
        );//end of updateLes method call.        
    }
    
}
